package de.stefanocke.roo.kontaktliste.web.common;

import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.extensions.markup.html.repeater.util.SingleSortState;

import de.stefanocke.roo.wicket.RooStereotype;

/**
 * A data provider that might be sortable or not. Base class for all
 * DataProviders.
 */
@RooStereotype("wicket.DataProvider")
public abstract class DataProviderBase<T> implements ISortableDataProvider<T, String> {

	private static final long serialVersionUID = 1L;

	private ISortState<String> sortState = new SingleSortState<String>();

	public DataProviderBase() {
		super();
	}

	/**
	 * {@inheritDoc} If the DataProvider does not support sorting, null is
	 * returned here.
	 */
	@Override
	public ISortState<String> getSortState() {
		if (isSortable()) {
			return sortState;
		} else {
			return null;
		}
	}

	/**
	 * To be overridden by subclasses.
	 * 
	 * @return true if the DataProvider supports sorting.
	 */
	public boolean isSortable() {
		return false;
	}
}
